<?php

namespace yan\backendclient\modules\role\models;

use Yii;

/**
 * This is the model class for table "{{%backend_role_rule}}".
 *
 * @property integer $id
 * @property integer $role_id
 * @property string $control
 * @property string $alias_name
 * @property string $type
 */
class RoleRule extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%backend_role_rule}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['role_id', 'control'], 'required'],
            [['role_id'], 'integer'],
            [['control'], 'string', 'max' => 255],
            [['alias_name'], 'string', 'max' => 100],
            [['type'], 'string', 'max' => 24],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('debug', 'ID'),
            'role_id' => Yii::t('debug', '角色ID '),
            'control' => Yii::t('debug', '权限控制'),
            'alias_name' => Yii::t('debug', '别名'),
            'type' => Yii::t('debug', '类型'),
        ];
    }

    // 获取角色列表
    public function dropDownRoleList(){
        $models = Role::find()->asArray()->all();
        $arr = [];
        foreach ($models as $key => $val) {
            $arr[$val['id']] = $val['name'];
        }
        return $arr;
    }
}
